import unittest
from common import HTMLTestRunner
class Mydemo(unittest.TestCase):
    def tearDown(self):
        print('111')

    def setUp(self):
        print(22222)

    def test1(self):
        print('testrun')

    def test2(self):
        print('testrun2')
        self.assertEqual(1, -1)

    def test3(self):
        print("test1")
if __name__ == '__main__':
    suit = unittest.TestSuite()
    suit.addTest(Mydemo("test1"))
    suit.addTest(Mydemo("test2"))
    # runner1 = unittest.TextTestRunner(stream=None, descriptions=None, verbosity=2)
    # runner1.run(suit)  # 运行测试用例
    # fp = open('/Users/qts/Downloads/interfaceTest/result/20190225144150/report.html', 'wb')  # 打开一个保存结果的html文件
    # runner2 = HTMLTestRunner.HTMLTestRunner(stream=fp, title='api测试报告', description='测试情况')
    # # print("111")
    # runner2.run(suit)

    with open('/Users/qts/Downloads/interfaceTest/result/20190225144150/report.html', 'wb') as file:  # html文件必须以二进制方式写入
        runner = HTMLTestRunner.HTMLTestRunner(stream=file,
                                                  title='测试报告',
                                                  description='这是第一次执行用例的测试报告')
        runner.run(suit)
